import request from '@/utils/request'
import type { Response } from '@/api/type'
import { AttrValueList, AttrList, AttrValueVO } from './type'

enum API {
  // 获取获取一级分类的接口
  GET_CATEGORY_1 = '/admin/product/getCategory1',
  // 获取获取二级分类的接口
  GET_CATEGORY_2 = '/admin/product/getCategory2',
  // 获取获取三级分类的接口
  GET_CATEGORY_3 = '/admin/product/getCategory3',
  // 获取获取属性列表的接口
  GET_ATTR_INFO_LIST = '/admin/product/attrInfoList',
  // 添加或者修改已有的属性的接口
  ADD_OR_UPDATE_ATTR = '/admin/product/saveAttrInfo',
  // 删除属性的接口
  DELETE_ATTR = '/admin/product/deleteAttr',
}

// 获取一级分类的接口
export const getCategory1 = () => request.get<any, Response<AttrList>>(API.GET_CATEGORY_1)
// 获取二级分类的接口
export const getCategory2 = (category1Id: number) => request.get<any, Response<AttrList>>(`${API.GET_CATEGORY_2}/${category1Id}`)
// 获取三级分类的接口
export const getCategory3 = (category2Id: number) => request.get<any, Response<AttrList>>(`${API.GET_CATEGORY_3}/${category2Id}`)

// 获取属性列表的接口
export const getAttrInfoList = (category1Id: number, category2Id: number, category3Id: number) => request.get<any, Response<AttrValueList>>(`${API.GET_ATTR_INFO_LIST}/${category1Id}/${category2Id}/${category3Id}`)
// 添加或者修改已有的属性的接口
export const addOrUpdateAttr = (data: AttrValueVO) => request.post<any, Response<any>>(API.ADD_OR_UPDATE_ATTR, data)
// 删除属性的接口
export const deleteAttr = (attrId: number) => request.delete<any, Response<any>>(`${API.DELETE_ATTR}/${attrId}`)